import { http } from "@/utils/http";
import { globalDataStoreHook } from "@/store/modules/globalData";

// const baseUrl = VITE_REQUEST_BASE_YST;

const initCityId = globalDataStoreHook().cityId;

type healthManageOverview = {
  result: {
    list: {
      cityId: number;
      highRiskNumber: number;
      highRiskPercent: number;
      mngtMember: number;
      program: string;
    }[];
    totalmemNum: number;
    totalprogram: number;
  };
  [prop: string]: any;
};

type healthManageInfo = {
  result: {
    data: {
      cityId: number;
      highRiskNumber: number;
      highRiskPercent: number;
      mngtMember: number;
      program: string;
    }[];
  };
  [prop: string]: any;
};

export type allMemberDetailResultType = {
  result: {
    data: {
      cityId: number;
      cityName: string;
      highRiskProgramNumber: number;
      memberId: string;
      memberName: string;
    }[];
    totalSize: number;
  };
};

/**
 * 健康管理-管理概况
 * */
export function getHealthManageOverview(cityId = initCityId) {
  return http.request<healthManageOverview>(
    "get",
    `http://analyse.wanhuhealth.com/second/api/program/getProgramOverview?cityId=${cityId}`
  );
  // fetch(
  //   "http://analyse.wanhuhealth.com/second/api/program/getProgramOverview?cityId=340200"
  // )
  //   .then(res => {
  //     return res.json();
  //   })
  //   .then(res2 => {
  //     console.log("res2:", res2);
  //   });
}
/**
 * 健康管理-管理概况-再住院
 * http://analyse.wanhuhealth.com/second/api/program/getProgramInfo?cityId=340200&tablename=readmission_stats&page=1&size=10
 */

/**
 * 健康管理-管理概况-慢病管理
 * http://analyse.wanhuhealth.com/second/api/program/getProgramInfo?cityId=340200&tablename=chronic_stats&page=1&size=10
 */

/**
 * 健康管理-管理概况-慢性疾病用药依从性管理
 * http://analyse.wanhuhealth.com/second/api/program/getProgramInfo?cityId=340200&tablename=chronic_med_stats&page=1&size=10
 */

/**
 * 健康管理-管理概况-指定药物依从性管理
 * http://analyse.wanhuhealth.com/second/api/program/getProgramInfo?cityId=340200&tablename=sp_med_stats&page=1&size=10
 */
export function getHealthManageInfo(tablename, cityId = initCityId) {
  return http.request<healthManageInfo>(
    "get",
    `http://analyse.wanhuhealth.com/second/api/program/getProgramInfo?cityId=${cityId}&tablename=${tablename}&page=1&size=10`
  );
}

/**
 * 健康管理-管理概况-高风险人群数
 *
 */
export function getAllMemberDetail(cityId = initCityId) {
  return http.request<allMemberDetailResultType>(
    "get",
    `http://analyse.wanhuhealth.com/second/api/member/getAllMemberDetail?cityId=${cityId}&page=1&size=10`
  );
}

/**
 * 居民健康-管理概览-首页
 * http://analyse.wanhuhealth.com/api/onecity/getindexvalue?cityId=340200
 */
type healthIndexOverviewResultType = {
  result: {
    metrics: string;
    value: number;
  }[];
  [prop: string]: any;
};
export function getHealthIndexOverview(cityId = initCityId) {
  // console.log("getHealthIndexOverview cityId:", cityId);
  // console.log("getHealthIndexOverview initCityId:", initCityId);
  return http.request<healthIndexOverviewResultType>(
    "get",
    `http://analyse.wanhuhealth.com/api/onecity/getindexvalue?cityId=${cityId}`
  );
}

export type RiskDataType = {
  data: number[];
  xaxis: string[];
};

export type RiskResultType = {
  result: RiskDataType;
};

/**
 * 居民健康-管理概览-用户画像 健康风险比例，按人数
 * http://analyse.wanhuhealth.com/api/onecity/managedmemcntrisk?cityId=340200
 */
export function getHealthIndexHospitalRiskByNum(cityId = initCityId) {
  return http.request<RiskResultType>(
    "get",
    `http://analyse.wanhuhealth.com/api/onecity/managedmemcntrisk?cityId=${cityId}`
  );
}

/**
 * 居民健康-管理概览-用户画像 健康风险比例，按医疗支出
 * http://analyse.wanhuhealth.com/api/onecity/managedmemriskpct?cityId=340200
 */

export function getHealthIndexHospitalRiskByMedical(cityId = initCityId) {
  return http.request<RiskResultType>(
    "get",
    `http://analyse.wanhuhealth.com/api/onecity/managedmemriskpct?cityId=${cityId}`
  );
}

/**
 * 居民健康-管理概览-用户画像-管理会员人数占比 - 按人数
 * http://analyse.wanhuhealth.com/api/onecity/managedmemdesasecnt?cityId=340200
 */

export function getHealthIndexMemberRatioByNum(cityId = initCityId) {
  return http.request<RiskResultType>(
    "get",
    `http://analyse.wanhuhealth.com/api/onecity/managedmemdesasecnt?cityId=${cityId}`
  );
}

/**
 * 居民健康-管理概览-用户画像-管理会员人数占比-按医疗支出
 * http://analyse.wanhuhealth.com/api/onecity/managedmemdesasecnt?cityId=340200
 */

export function getHealthIndexMemberRatioByMedical(cityId = initCityId) {
  return http.request<RiskResultType>(
    "get",
    `http://analyse.wanhuhealth.com/api/onecity/managedmemdesasecntall?cityId=${cityId}`
  );
}

type memberTotalType = {
  result: {
    city: string;
    cityId: number;
    value: number;
  };
};

// 管理概览-管理居民总数 http://analyse.wanhuhealth.com/api/showData3_2/getMemberTotalByYear?productId=bmi
export function getMemberNum(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/showData3_2/getMemberTotalByCity?cityId=${cityId}&productId=bmi`;
  return http.request<memberTotalType>("get", url);
}

// 管理概览-慢性病改善 http://analyse.wanhuhealth.com/api/showData3_2/getChrBetterMemsByCity?cityId=340200&productId=bmi

export function getChronicDiseaseBetterNum(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/showData3_2/getChrBetterMemsByCity?cityId=${cityId}&productId=bmi`;
  return http.request<memberTotalType>("get", url);
}

// 管理概览-用药改善 http://analyse.wanhuhealth.com/api/showData3_2/getMedBetterMemsByCity?cityId=340200&productId=bmi

export function getUseDrugBetterNum(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/showData3_2/getMedBetterMemsByCity?cityId=${cityId}&productId=bmi`;
  return http.request<memberTotalType>("get", url);
}
// 会员满意度
export function getMemOkNum(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/showData3_2/getMemberManagerMemsat?cityId=${cityId}&productId=bmi`;
  return http.request<memberTotalType>("get", url);
}

// 获取血压达标率 http://analyse.wanhuhealth.com/api/onecity/controlledbp?cityId=340200

export function getXyRate(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/onecity/controlledbp?cityId=${cityId}`;
  return http.request<healthIndexOverviewResultType>("get", url);
}

export function getXtRate(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/onecity/controlledbg?cityId=${cityId}`;
  return http.request<healthIndexOverviewResultType>("get", url);
}

export function getXzRate(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/onecity/controlledldl?cityId=${cityId}`;
  return http.request<healthIndexOverviewResultType>("get", url);
}

// 避免住院人次按疾病分布 http://analyse.wanhuhealth.com/api/onecity/managedmemavoidvent?cityId=340200
export function getReHospitalDataByNum(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/onecity/managedmemavoidvent?cityId=${cityId}`;
  return http.request<RiskResultType>("get", url);
}
// 避免住院支出金额按疾病分布
export function getReHospitalDataByMedical(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/onecity/managedmemavoidcost?cityId=${cityId}`;
  return http.request<RiskResultType>("get", url);
}

// 重疾早发现人数
export function getSeriousIllnessDataByNum(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/onecity/savedcostcnt?cityId=${cityId}`;
  return http.request<RiskResultType>("get", url);
}
// 重疾早发现人数
export function getSeriousIllnessDataByMedical(cityId = initCityId) {
  const url = `http://analyse.wanhuhealth.com/api/onecity/savedcostcost?cityId=${cityId}`;
  return http.request<RiskResultType>("get", url);
}
